package com.hsogoo.avatar.registry;

import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import com.google.common.collect.Maps;
import com.hsogoo.avatar.control.LimitControl;

/**
 * Created by za-huangsaigang on 2018/10/30.
 */
public class LimitControlRegistry {

    private static Lock lock = new ReentrantLock();

    private static Map<String, LimitControl> limitControlRegistry = Maps.newConcurrentMap();

    public static void register(String key, LimitControl limitControl){
        if(!limitControlRegistry.containsKey(key)){
            lock.lock();
            try{
                limitControlRegistry.put(key, limitControl);
            }finally {
                lock.unlock();
            }
        }
    }

    public static LimitControl getLimitControl(String key){
        return limitControlRegistry.get(key);
    }
}
